<?php
namespace common\core\base;

use yii\filters\auth\HttpBearerAuth;
use yii\rest\Controller;

/**
 * Class BaseApiController
 * 
 * @author Xuegui Yuan <yuanxuegui@163.com>
 */
class BaseApiController extends Controller
{

    /**
     *
     * @var bool
     */
    public $needLogin = false;

    /**
     * @inheritdoc
     *
     * @var string
     */
    public $serializer = [
        'class' => 'yii\rest\Serializer',
        'collectionEnvelope' => 'items'
    ];

    /**
     * @inheritdoc
     *
     * @return array
     */
    public function behaviors()
    {
        $behaviors = parent::behaviors();
        
        if ($this->needLogin) {
            $behaviors['authenticator'] = [
                'class' => HttpBearerAuth::className()
            ];
        }
        
        return $behaviors;
    }
}